package com.company.behavioral.memento_pattern.client;

import com.company.behavioral.memento_pattern.caretaker.MementoCaretaker;
import com.company.behavioral.memento_pattern.originator.Chessman;

/**
 * @ClassName Client
 * @Author tiezheng.han
 * @Date 2020/9/4 18:18
 **/
public class Client {
    public static void main(String[] args) {
        MementoCaretaker mc = new MementoCaretaker();
        Chessman chess = new Chessman("车",1,1);
        display(chess);
        // 保存状态
        mc.setMemento(chess.save());
        chess.setY(4);
        display(chess);
        // 保存状态
        mc.setMemento(chess.save());
        chess.setX(5);
        display(chess);
        System.out.println("*************悔棋**************");
        // 回复状态
        chess.restore(mc.getMemento());
        display(chess);
    }

    public static void display(Chessman chess){
        System.out.println("棋子" + chess.getLable() + "当前位置为：" + "第" + chess.getX() +
                "行" + "第" + chess.getY() + "列。");
    }
}
